package cn.edu.laud.sany.utils;

/**
 * 时间转化函数，主要用来将毫秒 纳秒转化为易看懂的格式
 * 
 * @author hxd
 * 
 */
public class TimeUtils
{
	/**
	 * 纳秒到 时分秒毫秒的转化显示
	 * 
	 * @param nanoSecond
	 * @return
	 */
	public static String nanoSecondToString(long nanoSecond)
	{
		StringBuilder sb = new StringBuilder(10);
		nanoSecond /= 1000000;
		int ms, sec, min;
		long hour;
		if (nanoSecond != 0)
		{
			ms = (int) (nanoSecond % 1000);
			nanoSecond /= 1000;
			sb.insert(0, ms + "ms");
			if (nanoSecond != 0)
			{
				sec = (int) (nanoSecond % 60);
				nanoSecond /= 60;
				sb.insert(0, sec + "s ");
				if (nanoSecond != 0)
				{
					min = (int) (nanoSecond % 60);
					nanoSecond /= 60;
					sb.insert(0, min + "m ");
					if (nanoSecond != 0)
					{
						hour = (int) (nanoSecond % 24);
						nanoSecond /= 24;
						sb.insert(0, hour + "h ");
					}
				}
			}
		}
		return sb.toString();
	}
	
}
